<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
import { getSign } from "./api/getData";

export default {
  name: "App",
  async created() {
    if (process.env.NODE_ENV === "production") {
      const code = this.getUrlParam("code");
      const current_url = location.href;

      if (!localStorage.getItem("sign")) {
        console.log('aaa')
        if (code === "" || code === null) {
          var api_url = "https://open.weixin.qq.com/connect/oauth2/authorize?";
          api_url += "appid=wx0edec802e549da24";
          api_url += "&redirect_uri=" + encodeURI(current_url);
          api_url += "&scope=snsapi_base&state=STATE#wechat_redirect";
          window.location = api_url;
        } else {
          const res = await getSign(code);
          localStorage.setItem("sign", res.data.data.data.sign)
          // this.$store.commit('changeIsGetSign');
          window.location = current_url
        }
      }
    }
  },
  methods: {
    getUrlParam(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
      var r = window.location.search.substr(1).match(reg); //匹配目标参数
      if (r != null) return decodeURI(r[2]);
      return null; //返回参数值
    }
  }
};
</script>
<style lang="less">
@import "~vux/src/styles/reset.less";
</style>
<style lang="scss">
#app {
  height: 100%;
  width: 100%;
}
</style>
